package com.jarchie.htgl.views;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;

import com.jarchie.htgl.R;
import com.jarchie.htgl.utils.ScreenUtil;

/**
 * Created by Jarchie on 2017\12\20.
 * 创建通用的自定义Dialog
 */

public class CommonDialog extends Dialog {

    private static final int WIDTH_PERCENT = 2;
    private static final int HEIGHT_PERCENT = 3;
    private String tag;

    //定义UI模板
    public CommonDialog(Context context, int layout) {
        this(context, layout, R.style.Theme_dialog, Gravity.CENTER);
    }

    //定义属性
    public CommonDialog(Context context, int layout, int style, int gravity) {
        super(context, style);
        //设置属性
        setContentView(layout);
        int deviceWidth = ScreenUtil.getScreenWidth();
        int deviceHeight = ScreenUtil.getScreenHeight();
        Window window = getWindow();
        WindowManager.LayoutParams layoutParams = window.getAttributes();
        layoutParams.width = deviceWidth / WIDTH_PERCENT;
        layoutParams.height = deviceHeight / HEIGHT_PERCENT;
        layoutParams.gravity = gravity;
        window.setAttributes(layoutParams);
    }

    public String getTag() {
        return tag;
    }

    public void setTag(String tag) {
        this.tag = tag;
    }

}
